package com.zcy.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class IterationTagDemo extends TagSupport {
	private String var;
	private String[] iterms;
	private int i = 1;

	public String getVar() {
		return var;
	}

	public void setVar(String var) {
		this.var = var;
	}

	public String[] getIterms() {
		return iterms;
	}

	public void setIterms(String[] iterms) {
		this.iterms = iterms;
	}

	@Override
	public int doStartTag() throws JspException {
		if (iterms != null && iterms.length > 0) {
			for (int j = 0; j < iterms.length; j++) {
				pageContext.setAttribute("name", iterms[j]);
			}
			return EVAL_BODY_INCLUDE;
		} else {
			return SKIP_BODY;
		}
	}

	@Override
	public int doAfterBody() throws JspException {
		if (i < iterms.length) {
			pageContext.setAttribute("name", iterms[i]);
			i++;
			return EVAL_BODY_AGAIN;
		} else {
			return SKIP_BODY;
		}
	}
	
}
